import { store} from '../store'
const loadFont = (app)=> {
  const font_uy = app.ossConfig('font_uy.ttf')
  const font_zh = app.ossConfig('font_zh.ttf')
  wx.loadFontFace({
    global: true,
    family: 'uy',
    source: `url("${font_uy}")`,
    success: (status) => {
      console.log('font loaded correctly: font_uy.ttf')
    },
    fail: (status) => {
      console.log('font load failed: font_uy.ttf')
    }
  })
  wx.loadFontFace({
    global: true,
    family: 'mama',
    source: `url("${font_zh}")`,
    success: (status) => {
      console.log('font loaded correctly: font_uy.ttf')
    },
    fail: (status) => {
      console.log('font load failed: font_uy.ttf')
    }
  })
}

const checkLang = () => {
  const key = 'lang';
  const langValue = wx.getStorageSync(key);
  if (!langValue || (langValue !== 'uy' && langValue !== 'zh')) {
      console.log('didnt find language ,going to language setting page')
      wx.redirectTo({
          url: '/pages/language-setting/language-setting',
      });
      return
  }
  store.updateLang(langValue)
};

module.exports = {checkLang, loadFont}
